﻿using System;
using YmtAuth.Domain.DomainEvent;
using YmtAuth.LogService;
using YmtSystem.CrossCutting;
using YmtSystem.Infrastructure.EventBusService;

namespace YmtAuth.EventHandler
{
    public class LoginSafeVerifyEventHandler : IEventSubscriber<LoginSafeVerifyEvent>
    {
        public void Error(Exception ex)
        {
            YmatouLoggingService.Error("LoginSafeVerifyEventHandler error， {0}", ex);
        }

        public void Handle(LoginSafeVerifyEvent domainEvent)
        {
            LogTask.Instance.EnQueue(new SafeVerifyLog
            {
                ApiId = domainEvent.ApiId,
                RequestId = domainEvent.RequestId,
                StrategyType = domainEvent.StrategyType,
                AppSource = domainEvent.AppSource,
                UserId = domainEvent.UserId,
                LoginId = domainEvent.LoginId,
                LoginIp = domainEvent.LoginIp,

                RunTime = domainEvent.RunTime,
                DeviceId = domainEvent.DeviceId,
                ClientId = domainEvent.ClientId,
                AuthType = domainEvent.AuthType,
                ResponseCode = domainEvent.ResponseCode,
                ResponseDesc = domainEvent.Desc,

                IpArea = domainEvent.IpArea,
                LastAuthTime = domainEvent.LastAuthTime,
                ExpiredTime = domainEvent.ExpiredTime                
            });
        }

        public EventHandlerStrategy Strategy
        {
            get { return new EventHandlerStrategy
                {
                    AsyncReceive =false            
                }; 
            }
        }
    }
}
